﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace Zad4
{
    class logika
    {
        public serwer serw = new serwer();
        Thread daemon;
        Thread northbound;
        Thread southbound;

        public logika()
        {
            daemon = new Thread(serw.daem);
            northbound = new Thread(northb);
            southbound = new Thread(southb);
            daemon.Start();
            northbound.Start();
            southbound.Start();
        }

        public void northb()
        {
            while (true)
            {
                Random rng = new Random();
                if (rng.Next(2)%2==0) serw.wejscieN();
                Thread.Sleep(rng.Next(2000));
            }
        }

        public void southb()
        {
            while (true)
            {
                Random rng = new Random();
                if (rng.Next(2) % 2 == 0) serw.wejscieS();
                Thread.Sleep(rng.Next(2000));
            }
        }

        public void killWatki()
        {
            southbound.Abort();
            northbound.Abort();
            daemon.Abort();
        }
    }
}
